/*******************************************************************
** This code is part of Breakout.
**
** Breakout is free software: you can redistribute it and/or modify
** it under the terms of the CC BY 4.0 license as published by
** Creative Commons, either version 4 of the License, or (at your
** option) any later version.
******************************************************************/
#ifndef _SPRITE_H
#define _SPRITE_H

#include "engine.h"
#include "opengl/opengl_buffer.h"
#include "opengl/opengl_shader.h"
#include "entity/entity2D.h"
namespace engine
{

    class Sprite : public Entity2D
    {
    public:
        Sprite(Shader *shader, Texture2D *texture)
            : Entity2D(shader, texture)
        {
            float vertices[] = {
                // pos      // tex
                0.5f, 0.5f, 0.0f,   // top right
                0.5f, -0.5f, 0.0f,  // bottom right
                -0.5f, -0.5f, 0.0f, // bottom left
                -0.5f, 0.5f, 0.0f,  // top left
            };
            float coor[] = {1.0f, 1.0f,
                            1.0f, 0.0f,
                            0.0f, 0.0f,
                            0.0f, 1.0f};

            unsigned int indices[] = {
                0, 1, 3, // first triangle
                1, 2, 3  // second triangle
            };

            this->vertexArray->addVertexBuffer(new VertexBuffer(vertices, sizeof(vertices)), 0, 3);
            this->vertexArray->addVertexBuffer(new VertexBuffer(coor, sizeof(coor)), 2, 2);
            this->vertexArray->addIndexBuffer(new IndexBuffer(indices, sizeof(indices)));
            vertexSize = 6;
        }
        // Destructor
        ~Sprite() {}
        // Renders a defined quad textured with given sprite
        //void render(Texture2D &texture, glm::vec2 position, glm::vec2 size = glm::vec2(10.0f, 10.0f), float rotate = 0.0f, glm::vec3 color = glm::vec3(1.0f));
        void drawIndex()
        {
            vertexArray->bind();
            glDrawElements(primitiveType, vertexSize, GL_UNSIGNED_INT, 0);
        }

    private:
        // Render state
        // Initializes and configures the quad's buffer and vertex attributes
        void initRenderData();
    };
}
#endif